package com.zhuiyun.project.api.trainingTime.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhuiyun.project.annotation.OptLog;

import com.zhuiyun.project.api.trainingTime.eneity.TrainingTime;
import com.zhuiyun.project.api.trainingTime.mapper.TrainingDateMapper;
import com.zhuiyun.project.api.trainingTime.model.TrainingTimeModel;
import com.zhuiyun.project.api.trainingTime.service.TrainingDateService;
import com.zhuiyun.project.common.errorCode.CommonException;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.constants.CommonConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;


/**
 * @ClassName TrainingTimeController
 * @Description TODO 我的时间安排
 * @Author fei
 * @Date 2023/12/11 14:43
 **/
@RestController
@Api(tags = "我的时间安排")
@RequestMapping("/trainingTime")
@Slf4j
public class TrainingDateController {

    @Autowired
    TrainingDateService trainingTimeService;

    @Autowired
    TrainingDateMapper trainingTimeMapper;

    /**
    * @Author fei
    * @Description 上课时间查询
    * @Date 2023/12/12 19:01
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param id
    */
    @GetMapping("/selectTrainingTime")
    @ApiOperation(value = "上课时间查询")
    @OptLog(modular = "上课时间", type = CommonConstants.SELECT, describe = "上课时间查询")
    public CommonResult selectTrainingTime(Integer id) {
        QueryWrapper<TrainingTime> queryWrapper = new QueryWrapper();
        queryWrapper.eq("coach_id",id);
        queryWrapper.eq("del_flag","0");
        List<TrainingTime> list = trainingTimeMapper.selectList(queryWrapper);
        return CommonResult.ok(list);
    }

    /**
    * @Author fei
    * @Description 上课时间的新增方法
    * @Date 2023/12/11 15:50
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param trainingTimeModel
    */
    @PostMapping("/saveTrainingTime")
    @ApiOperation(value = "上课时间的新增方法")
    @OptLog(modular = "上课时间的新增方法", type = CommonConstants.ADD, describe = "上课时间的新增方法")
    public CommonResult saveTrainingTime(@RequestBody TrainingTimeModel trainingTimeModel) throws CommonException {
        return trainingTimeService.saveTrainingTime(trainingTimeModel);
    }

    /**
    * @Author fei
    * @Description 上课时间的修改方法
    * @Date 2023/12/11 15:50
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param trainingTimeModel
    */
    @PutMapping("/updateTrainingTime")
    @ApiOperation(value = "上课时间的修改方法")
    @OptLog(modular = "上课时间的修改方法", type = CommonConstants.UPDATE, describe = "上课时间的修改方法")
    public CommonResult updateTrainingTime(@RequestBody TrainingTimeModel trainingTimeModel) throws CommonException {
        return trainingTimeService.updateTrainingTime(trainingTimeModel);
    }

    /**
    * @Author fei
    * @Description 删除上课时间
    * @Date 2023/12/12 19:01
    * @Return com.zhuiyun.project.common.response.CommonResult
    * @param id
    * @param coachId
    */
    @ApiOperation(value = "删除上课时间")
    @OptLog(modular = "删除上课时间",type = CommonConstants.DELETE,describe = "删除上课时间")

    @DeleteMapping("/deleteTrainingTime/{id}/{coachId}")
    public CommonResult deleteTrainingTime(@PathVariable Integer id, @PathVariable Integer coachId){
        return trainingTimeService.deleteTrainingTime(id,coachId);
    }


}
